﻿Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class frmNguoi_nop_nhan_tien
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnNew As System.Windows.Forms.Button
    Friend WithEvents btnSave As System.Windows.Forms.Button
    Friend WithEvents btnDelete1 As System.Windows.Forms.Button
    Friend WithEvents txtTen As System.Windows.Forms.TextBox
    Friend WithEvents txtMa As System.Windows.Forms.TextBox
    Friend WithEvents txtDiachi As System.Windows.Forms.TextBox
    Friend WithEvents BtnClose As System.Windows.Forms.Button
    Friend WithEvents DataGridView1 As System.Windows.Forms.DataGridView
    Friend WithEvents Label30 As System.Windows.Forms.Label
    Friend WithEvents Label31 As System.Windows.Forms.Label
    Friend WithEvents Label32 As System.Windows.Forms.Label
    Friend WithEvents Label33 As System.Windows.Forms.Label
    Friend WithEvents Label34 As System.Windows.Forms.Label
    Friend WithEvents Tbl_nguoi_nop_nhan_tienBindingSource As System.Windows.Forms.BindingSource
    Friend WithEvents DataSetSearch As PHUQUI.DataSetSearch
    Friend WithEvents MaDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents TenDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents DiachiDataGridViewTextBoxColumn As System.Windows.Forms.DataGridViewTextBoxColumn
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmNguoi_nop_nhan_tien))
        Dim DataGridViewCellStyle2 As System.Windows.Forms.DataGridViewCellStyle = New System.Windows.Forms.DataGridViewCellStyle
        Me.btnSave = New System.Windows.Forms.Button
        Me.txtDiachi = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.txtTen = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.txtMa = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnNew = New System.Windows.Forms.Button
        Me.btnDelete1 = New System.Windows.Forms.Button
        Me.BtnClose = New System.Windows.Forms.Button
        Me.Button1 = New System.Windows.Forms.Button
        Me.DataGridView1 = New System.Windows.Forms.DataGridView
        Me.DataSetSearch = New PHUQUI.DataSetSearch
        Me.Label30 = New System.Windows.Forms.Label
        Me.Label31 = New System.Windows.Forms.Label
        Me.Label32 = New System.Windows.Forms.Label
        Me.Label33 = New System.Windows.Forms.Label
        Me.Label34 = New System.Windows.Forms.Label
        Me.Tbl_nguoi_nop_nhan_tienBindingSource = New System.Windows.Forms.BindingSource(Me.components)
        Me.MaDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.TenDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        Me.DiachiDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataSetSearch, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Tbl_nguoi_nop_nhan_tienBindingSource, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnSave
        '
        Me.btnSave.BackColor = System.Drawing.Color.Transparent
        Me.btnSave.Image = CType(resources.GetObject("btnSave.Image"), System.Drawing.Image)
        Me.btnSave.Location = New System.Drawing.Point(222, 133)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(96, 24)
        Me.btnSave.TabIndex = 4
        Me.btnSave.UseVisualStyleBackColor = False
        '
        'txtDiachi
        '
        Me.txtDiachi.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtDiachi.Location = New System.Drawing.Point(112, 95)
        Me.txtDiachi.MaxLength = 100
        Me.txtDiachi.Name = "txtDiachi"
        Me.txtDiachi.Size = New System.Drawing.Size(576, 22)
        Me.txtDiachi.TabIndex = 3
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(58, 95)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(54, 20)
        Me.Label4.TabIndex = 16
        Me.Label4.Text = "Địa chỉ"
        '
        'txtTen
        '
        Me.txtTen.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTen.Location = New System.Drawing.Point(283, 66)
        Me.txtTen.MaxLength = 50
        Me.txtTen.Name = "txtTen"
        Me.txtTen.Size = New System.Drawing.Size(405, 22)
        Me.txtTen.TabIndex = 2
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(256, 69)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(59, 16)
        Me.Label3.TabIndex = 14
        Me.Label3.Text = "Tên "
        '
        'txtMa
        '
        Me.txtMa.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtMa.Location = New System.Drawing.Point(112, 66)
        Me.txtMa.MaxLength = 10
        Me.txtMa.Name = "txtMa"
        Me.txtMa.Size = New System.Drawing.Size(144, 22)
        Me.txtMa.TabIndex = 1
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(61, 69)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(51, 16)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "Mã "
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(194, 13)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(404, 24)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "DANH MỤC NHÂN VIÊN NỘP - NHẬN TIỀN"
        '
        'btnNew
        '
        Me.btnNew.Image = CType(resources.GetObject("btnNew.Image"), System.Drawing.Image)
        Me.btnNew.Location = New System.Drawing.Point(112, 133)
        Me.btnNew.Name = "btnNew"
        Me.btnNew.Size = New System.Drawing.Size(96, 24)
        Me.btnNew.TabIndex = 5
        '
        'btnDelete1
        '
        Me.btnDelete1.Image = CType(resources.GetObject("btnDelete1.Image"), System.Drawing.Image)
        Me.btnDelete1.Location = New System.Drawing.Point(333, 133)
        Me.btnDelete1.Name = "btnDelete1"
        Me.btnDelete1.Size = New System.Drawing.Size(96, 24)
        Me.btnDelete1.TabIndex = 29
        '
        'BtnClose
        '
        Me.BtnClose.Image = CType(resources.GetObject("BtnClose.Image"), System.Drawing.Image)
        Me.BtnClose.Location = New System.Drawing.Point(554, 133)
        Me.BtnClose.Name = "BtnClose"
        Me.BtnClose.Size = New System.Drawing.Size(96, 24)
        Me.BtnClose.TabIndex = 30
        '
        'Button1
        '
        Me.Button1.Image = CType(resources.GetObject("Button1.Image"), System.Drawing.Image)
        Me.Button1.Location = New System.Drawing.Point(442, 133)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(96, 24)
        Me.Button1.TabIndex = 39
        '
        'DataGridView1
        '
        Me.DataGridView1.AllowUserToAddRows = False
        Me.DataGridView1.AllowUserToDeleteRows = False
        Me.DataGridView1.AllowUserToResizeColumns = False
        Me.DataGridView1.AutoGenerateColumns = False
        Me.DataGridView1.BackgroundColor = System.Drawing.Color.LightBlue
        DataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter
        DataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control
        DataGridViewCellStyle2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        DataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText
        DataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight
        DataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText
        DataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.[True]
        Me.DataGridView1.ColumnHeadersDefaultCellStyle = DataGridViewCellStyle2
        Me.DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
        Me.DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Me.MaDataGridViewTextBoxColumn, Me.TenDataGridViewTextBoxColumn, Me.DiachiDataGridViewTextBoxColumn})
        Me.DataGridView1.DataMember = "tbl_nguoi_nop_nhan_tien"
        Me.DataGridView1.DataSource = Me.DataSetSearch
        Me.DataGridView1.Location = New System.Drawing.Point(3, 190)
        Me.DataGridView1.Name = "DataGridView1"
        Me.DataGridView1.ReadOnly = True
        Me.DataGridView1.RowHeadersWidth = 25
        Me.DataGridView1.Size = New System.Drawing.Size(787, 382)
        Me.DataGridView1.TabIndex = 41
        '
        'DataSetSearch
        '
        Me.DataSetSearch.DataSetName = "DataSetSearch"
        Me.DataSetSearch.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema
        '
        'Label30
        '
        Me.Label30.AutoSize = True
        Me.Label30.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label30.ForeColor = System.Drawing.Color.DarkGreen
        Me.Label30.Location = New System.Drawing.Point(587, 160)
        Me.Label30.Name = "Label30"
        Me.Label30.Size = New System.Drawing.Size(33, 13)
        Me.Label30.TabIndex = 1120
        Me.Label30.Text = "Ctrl-Q"
        Me.Label30.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label31
        '
        Me.Label31.AutoSize = True
        Me.Label31.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label31.ForeColor = System.Drawing.Color.DarkGreen
        Me.Label31.Location = New System.Drawing.Point(477, 160)
        Me.Label31.Name = "Label31"
        Me.Label31.Size = New System.Drawing.Size(32, 13)
        Me.Label31.TabIndex = 1119
        Me.Label31.Text = "Ctrl-P"
        Me.Label31.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label32
        '
        Me.Label32.AutoSize = True
        Me.Label32.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label32.ForeColor = System.Drawing.Color.DarkGreen
        Me.Label32.Location = New System.Drawing.Point(366, 160)
        Me.Label32.Name = "Label32"
        Me.Label32.Size = New System.Drawing.Size(33, 13)
        Me.Label32.TabIndex = 1118
        Me.Label32.Text = "Ctrl-D"
        Me.Label32.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label33
        '
        Me.Label33.AutoSize = True
        Me.Label33.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label33.ForeColor = System.Drawing.Color.DarkGreen
        Me.Label33.Location = New System.Drawing.Point(254, 160)
        Me.Label33.Name = "Label33"
        Me.Label33.Size = New System.Drawing.Size(32, 13)
        Me.Label33.TabIndex = 1117
        Me.Label33.Text = "Ctrl-S"
        Me.Label33.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label34
        '
        Me.Label34.AutoSize = True
        Me.Label34.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label34.ForeColor = System.Drawing.Color.DarkGreen
        Me.Label34.Location = New System.Drawing.Point(144, 160)
        Me.Label34.Name = "Label34"
        Me.Label34.Size = New System.Drawing.Size(33, 13)
        Me.Label34.TabIndex = 1116
        Me.Label34.Text = "Ctrl-N"
        Me.Label34.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Tbl_nguoi_nop_nhan_tienBindingSource
        '
        Me.Tbl_nguoi_nop_nhan_tienBindingSource.DataSource = Me.DataSetSearch
        Me.Tbl_nguoi_nop_nhan_tienBindingSource.Position = 0
        '
        'MaDataGridViewTextBoxColumn
        '
        Me.MaDataGridViewTextBoxColumn.DataPropertyName = "ma"
        Me.MaDataGridViewTextBoxColumn.HeaderText = "Mã"
        Me.MaDataGridViewTextBoxColumn.Name = "MaDataGridViewTextBoxColumn"
        Me.MaDataGridViewTextBoxColumn.ReadOnly = True
        Me.MaDataGridViewTextBoxColumn.Width = 80
        '
        'TenDataGridViewTextBoxColumn
        '
        Me.TenDataGridViewTextBoxColumn.DataPropertyName = "ten"
        Me.TenDataGridViewTextBoxColumn.HeaderText = "Tên"
        Me.TenDataGridViewTextBoxColumn.Name = "TenDataGridViewTextBoxColumn"
        Me.TenDataGridViewTextBoxColumn.ReadOnly = True
        Me.TenDataGridViewTextBoxColumn.Width = 260
        '
        'DiachiDataGridViewTextBoxColumn
        '
        Me.DiachiDataGridViewTextBoxColumn.DataPropertyName = "diachi"
        Me.DiachiDataGridViewTextBoxColumn.HeaderText = "Địa chỉ"
        Me.DiachiDataGridViewTextBoxColumn.Name = "DiachiDataGridViewTextBoxColumn"
        Me.DiachiDataGridViewTextBoxColumn.ReadOnly = True
        Me.DiachiDataGridViewTextBoxColumn.Width = 380
        '
        'frmNguoi_nop_nhan_tien
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.LightBlue
        Me.ClientSize = New System.Drawing.Size(792, 573)
        Me.Controls.Add(Me.Label30)
        Me.Controls.Add(Me.Label31)
        Me.Controls.Add(Me.Label32)
        Me.Controls.Add(Me.Label33)
        Me.Controls.Add(Me.Label34)
        Me.Controls.Add(Me.DataGridView1)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.BtnClose)
        Me.Controls.Add(Me.txtDiachi)
        Me.Controls.Add(Me.txtTen)
        Me.Controls.Add(Me.txtMa)
        Me.Controls.Add(Me.btnDelete1)
        Me.Controls.Add(Me.btnNew)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Name = "frmNguoi_nop_nhan_tien"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Danh Muc Nhan Vien Nop- Nhan Tien"
        CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataSetSearch, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Tbl_nguoi_nop_nhan_tienBindingSource, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Dim myDT As New DataTable
    Dim strError As String = ""
    Dim myform As Form
    Dim sqlQuery As String = ""
    Sub SetclearData()
        txtMa.Text = ""
        txtTen.Text = ""
        txtDiachi.Text = ""
    End Sub
    Private Sub txtMa_NHOM_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMa.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.txtTen.Focus()
        End If
    End Sub
    Private Sub txtTen_NHOM_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTen.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.txtDiachi.Focus()
        End If
    End Sub
    Private Sub txtGchu_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDiachi.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.btnSave.Focus()
        End If
    End Sub
    Private Sub btnSave_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles btnSave.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.btnNew.Focus()
        End If
    End Sub
    Private Sub btnNew_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles btnNew.KeyDown
        If e.KeyCode = Keys.Enter Then
            Me.txtMa.Focus()
        End If
    End Sub
    Private Sub frmNguoi_nop_nhan_tien_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        'tao moi
        If e.KeyCode = (e.Control And Keys.N) Then
            SetclearData()
            txtMa.Focus()
        End If
        'Luu
        If e.KeyCode = (e.Control And Keys.S) Then
            luu()
        End If
        'Xoa
        If e.KeyCode = (e.Control And Keys.D) Then
            xoa()
        End If
        'Thoat
        If e.KeyCode = (e.Control And Keys.Q) Then
            Me.Close()
        End If
        If e.KeyCode = (e.Control And Keys.P) Then
            ' FrmCrNhomtaikhoan.Show()
        End If
    End Sub

    Private Sub frmNguoi_nop_nhan_tien_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        'tao moi
        If e.KeyCode = (e.Control And Keys.N) Then
            SetclearData()
            txtMa.Focus()
        End If
        'Luu
        If e.KeyCode = (e.Control And Keys.S) Then
            luu()
        End If
        'Xoa
        If e.KeyCode = (e.Control And Keys.D) Then
            xoa()
        End If
        'Thoat
        If e.KeyCode = (e.Control And Keys.Q) Then
            Me.Close()
        End If
        If e.KeyCode = (e.Control And Keys.P) Then
            '  FrmCrNhomtaikhoan.Show()
        End If
    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        luu()
    End Sub
    Private Sub luu()
        ' Kiểm tra có nhập liệu chưa ?
        If Me.checkInput(txtMa.Text, txtTen.Text) Then
            Dim txtMaNhom = Me.txtMa.Text.Trim
            sqlQuery = "SELECT ma FROM tbl_nguoi_nop_nhan_tien WHERE ma = '" & txtMaNhom & "'"
            Dim existedMamon As Integer = moduleDatabaseConn.CheckRecordExisted(sqlQuery)
            If existedMamon = 1 Then ' Update record
                sqlQuery = "UPDATE tbl_nguoi_nop_nhan_tien "
                sqlQuery += "SET "
                sqlQuery += "ma = '" & txtMaNhom & "'"
                sqlQuery += ", ten = '" & Me.txtTen.Text.Trim & "'"
                sqlQuery += ", diachi = '" & Me.txtDiachi.Text.Trim & "'"
                sqlQuery += " WHERE ma = '" & txtMaNhom & "'"
                Dim updated As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If updated = 1 Then
                    MessageBox.Show("Cập nhật thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_nguoi_nop_nhan_tien "
                    Me.loadDanhSachNhomTaikhoan(sqlQuery)
                Else
                    MessageBox.Show("Cập nhật thông tin không thành công: " & globalVariale.sqlMsgError)
                End If
            Else
                If existedMamon = 0 Then ' Insert record
                    sqlQuery = "INSERT INTO tbl_nguoi_nop_nhan_tien "
                    sqlQuery += "(ma, ten,diachi) "
                    sqlQuery += "VALUES "
                    sqlQuery += "("
                    sqlQuery += "'" & txtMaNhom.ToUpper & "', "
                    sqlQuery += "'" & Me.txtTen.Text.Trim & "', "
                    sqlQuery += "'" & Me.txtDiachi.Text.Trim & "'"
                    sqlQuery += ")"
                    Dim inserted As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                    If inserted = 1 Then
                        MessageBox.Show("Thêm thông tin thành công !")
                        sqlQuery = "SELECT * FROM tbl_nguoi_nop_nhan_tien "
                        Me.loadDanhSachNhomTaikhoan(sqlQuery)
                    Else
                        MessageBox.Show("Thêm thông tin không thành công: " & globalVariale.sqlMsgError)
                    End If
                Else ' SQLExeption: existedMaQuocGia = -1
                    MessageBox.Show("Lấy dữ liệu bị lỗi: " & globalVariale.sqlMsgError, "Lấy dữ liệu", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
            End If
        End If
    End Sub
    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        SetclearData()
        txtMa.Focus()
    End Sub
    Private Sub btnDelete1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete1.Click
        xoa()
    End Sub
    Private Sub xoa()
        Dim txtMaNhom As String = Trim(Me.txtMa.Text)
        If txtMaNhom = "" Then
            MessageBox.Show("Bạn chưa chọn Mã để xóa !")
        Else
            Dim txtTenNhom As String = Trim(Me.txtTen.Text)
            moduleConstants.MessageWarning = "Bạn có muốn xóa " & txtMaNhom & "(" & txtTenNhom & ") ?"

            If MessageBox.Show(moduleConstants.MessageWarning, globalVariale.msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = MsgBoxResult.Yes Then
                Dim sqlQuery As String = "DELETE FROM tbl_nguoi_nop_nhan_tien WHERE ma = '" & txtMaNhom & "'"
                Dim deleting As Integer = moduleDatabaseConn.ExecuteNonQuery(sqlQuery)
                If deleting = 1 Then
                    MessageBox.Show("Xóa thông tin thành công !")
                    sqlQuery = "SELECT * FROM tbl_nguoi_nop_nhan_tien"
                    Me.loadDanhSachNhomTaikhoan(sqlQuery)
                    SetclearData()
                Else
                    MessageBox.Show("Xóa thông tin không thành công: " & globalVariale.sqlMsgError)
                End If
            End If
        End If
    End Sub
    Private Sub frmNguoi_nop_nhan_tien_load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        moduleUtils.setDinhDangVietNam()
        Me.KeyPreview = True
        Me.loadDanhSachNhomTaikhoan("SELECT * FROM tbl_nguoi_nop_nhan_tien ")
    End Sub
    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Me.Close()
    End Sub
    Function checkInput(ByVal ma As String, ByVal ten As String) As Boolean
        Dim result As Boolean = True
        If ma = "" Then
            MessageBox.Show("Bạn chưa chọn Mã Nhóm tài khoản !")
            result = False
        Else
            If ten = "" Then
                MessageBox.Show("Bạn chưa nhập tên Nhóm tài khoản!")
                result = False
            End If
        End If
        Return result
    End Function

    Private Sub loadDanhSachNhomTaikhoan(ByVal sqlQuery As String)
        Me.DataGridView1.DataSource = moduleDatabaseConn.GetDataTable(sqlQuery)
    End Sub

    Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim iRow As Integer = Me.DataGridView1.CurrentRow.Index
        Me.txtMa.Text = Me.DataGridView1.Item(0, iRow).Value
        Me.txtTen.Text = Me.DataGridView1.Item(1, iRow).Value
        Me.txtDiachi.Text = Me.DataGridView1.Item(2, iRow).Value
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'FrmCrNhomtaikhoan.Show()
    End Sub
End Class


